﻿Public Class altaCliente

    Private Sub altaCliente_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LimpiarFormulario()
        CargarCmb()
        'programar para cada txtbox la ayuda al ingreso
    End Sub

    Private Sub LimpiarFormulario()
        txtDNI.Text = ""
        txtApe.Text = ""
        txtNom.Text = ""
        txtDir.Text = ""
        txtNoDir.Text = ""
        txtPiso.Text = ""
        txtTel.Text = ""
        txtEmail.Text = ""
        txtCuit.Text = ""
    End Sub

    Private Sub CargarCmb()
        cmbTipoCli.Items.Add("Particular")
        cmbTipoCli.Items.Add("Empresa")
        cmbTipoCli.SelectedIndex = 0
    End Sub

    Private Sub btnAltaSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAltaSalir.Click
        If Guardar() Then
            Me.Close()
        End If
    End Sub

    Private Function Guardar() As Boolean
        Dim Cliente As New clsCliente()
        Dim Dao_Cliente As New daoCliente()

        Try
            Cliente.Dni = txtDNI.Text
            Cliente.Cuit = txtCuit.Text
            Cliente.Nombre = txtNom.Text
            Cliente.Apellido = txtApe.Text
            Cliente.Direccion = txtDir.Text
            Cliente.Altura = txtNoDir.Text
            Cliente.Depto = txtPiso.Text
            Cliente.Tel = txtTel.Text
            Cliente.Email = txtEmail.Text
            Cliente.Cod_Suc = Configuracion.Cod_Suc

            Select Case cmbTipoCli.SelectedText.ToUpper.Trim
                Case "PARTICULAR"
                    Cliente.Tipo = "P"
                Case "EMPRESA"
                    Cliente.Tipo = "E"
                Case Else
                    Cliente.Tipo = "P"
            End Select

            Cliente.Cli_Id = Numerador.TraeProximo("CLIENTE")
            If Dao_Cliente.Alta(Cliente) Then
                MessageBox.Show("El Cliente se a guardado Correctamente con el Número " & Convert.ToString(Cliente.Cli_Id).Trim.ToUpper, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return True
            Else
                MessageBox.Show("No se a guardado el Cliente. Comunicar a Sistemas", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return False
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        'Empiezo a asignar los datos al producto
    End Function

    Private Sub btnAltaNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAltaNuevo.Click
        If Guardar() Then
            LimpiarFormulario()
        End If
    End Sub

    Private Sub txtDNI_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDNI.KeyPress
        validarInt(e)
    End Sub

    Private Sub txtCuit_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCuit.KeyPress
        validarInt(e)
    End Sub

    Private Sub txtNom_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNom.KeyPress
        validarString(e)
    End Sub

    Private Sub txtApe_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtApe.KeyPress
        validarString(e)
    End Sub

    Private Sub txtNoDir_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNoDir.KeyPress
        validarInt(e)
    End Sub
    Private Sub txtTel_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTel.KeyPress
        validarTelefono(e)
    End Sub
End Class